//
//  SearchGiftCollectionViewCell.m
//  Present
//
//  Created by dllo on 15/10/8.
//  Copyright (c) 2015年 Lemon. All rights reserved.
//

#import "SearchGiftCollectionViewCell.h"
#import "SearchGiftModel.h"
#import "CategoryDetailModel.h"

@implementation SearchGiftCollectionViewCell



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self creataSubviews];
    }
    return  self;
}

- (void)creataSubviews
{
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    //图片
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height / 3 * 2)];
    //self.imageView.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.imageView];
  
    
    //名字
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.imageView.frame.size.height, self.imageView.frame.size.width - 10, self.contentView.frame.size.height / 3 / 3 * 2)];
    //self.nameLabel.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.nameLabel];

    
    //价钱
    self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.imageView.frame.size.height + self.nameLabel.frame.size.height, self.nameLabel.frame.size.width / 2 - 10, self.contentView.frame.size.height - self.imageView.frame.size.height - self.nameLabel.frame.size.height)];
    //self.priceLabel.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.priceLabel];
    
    //爱心
    self.heartImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.priceLabel.frame.size.width + self.priceLabel.frame.size.width / 3, self.priceLabel.frame.origin.y, self.priceLabel.frame.size.height, self.priceLabel.frame.size.height)];
    self.heartImageView.image = [[UIImage imageNamed:@"xihuan"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//取消渲染
    //self.heartImageView.backgroundColor = [UIColor blackColor];
    [self.contentView addSubview:self.heartImageView];
   
    
    //喜欢
    self.likeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.heartImageView.frame.origin.x + self.heartImageView.frame.size.width + 3, self.heartImageView.frame.origin.y, self.contentView.frame.size.width - self.heartImageView.frame.origin.x - self.heartImageView.frame.size.width - 3, self.heartImageView.frame.size.height)];
    //self.likeLabel.backgroundColor = [UIColor greenColor];
    [self.contentView addSubview:self.likeLabel];
  
    
    
}

- (void)setSearchGiftModel:(SearchGiftModel *)searchGiftModel
{
    _searchGiftModel = searchGiftModel;

    [self.imageView sd_setImageWithURL:[NSURL URLWithString:_searchGiftModel.cover_image_url]];
    
    self.nameLabel.text = _searchGiftModel.name;
    self.nameLabel.textAlignment = NSTextAlignmentLeft;
    self.nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.nameLabel.numberOfLines = 0;
    self.nameLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
    
    
    self.priceLabel.text = _searchGiftModel.price;
    self.priceLabel.textAlignment = NSTextAlignmentLeft;
    self.priceLabel.textColor = [UIColor redColor];
    self.priceLabel.font = [UIFont systemFontOfSize:17];
    
    self.likeLabel.text = [NSString stringWithFormat:@"%ld",_searchGiftModel.favorites_count];
    self.likeLabel.textColor = [UIColor lightGrayColor];
}
-(void)setCateDetail:(CategoryDetailModel *)cateDetail
{
    _cateDetail = cateDetail;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:cateDetail.cover_image_url]];
    
    self.nameLabel.text = cateDetail.name;
    self.nameLabel.textAlignment = NSTextAlignmentLeft;
    self.nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.nameLabel.numberOfLines = 0;
    self.nameLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
    
    
    self.priceLabel.text = cateDetail.price;
    self.priceLabel.textAlignment = NSTextAlignmentLeft;
    self.priceLabel.textColor = [UIColor redColor];
    self.priceLabel.font = [UIFont systemFontOfSize:17];
    
    self.likeLabel.text = [NSString stringWithFormat:@"%ld",cateDetail.favorites_count];
    self.likeLabel.textColor = [UIColor lightGrayColor];
}
@end
